package liudan.archetype.xmlutil;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * Email: liudan@ucfgroup.com
 * Title
 * Copyright: Copyright (c) 2017
 * User: liudan
 * Created on 2017/3/5 17:07
 */
public class ConfingBeans {

    /**
     * 读取配置文件
     *
     * @return
     * @throws DocumentException
     */
    public static Map<String, String> readConfig(String url) throws DocumentException {
        Map<String, String> beanMap = new HashMap<String, String>();
        SAXReader reader = new SAXReader();
        Document document = reader.read(url);
        Element root = document.getRootElement();
        List<Element> actionList = root.elements("component-scan");
        for (Element e : actionList) {
            beanMap.put("action-package", e.attribute("action-package").getValue());
        }
        List<Element> formList = root.elements("form-scan");
        for (Element e : formList) {
            beanMap.put("form-package", e.attribute("form-package").getValue());
        }

        return beanMap;
    }
}
